//
//  DB_Router.m
//  RacMVVM
//
//  Created by 崔博 on 2018/11/28.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "DB_Router.h"

@interface DB_Router()
@property(nonatomic, strong) NSDictionary *viewModelViewMappings; // viewModel到view的映射
@end
@implementation DB_Router
 + (instancetype)sharedInstance
{
    static DB_Router * shareInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
         shareInstance = [[self alloc] init];
    });
    return shareInstance;
}
- (DB_BaseViewController *)viewControllerForViewModel:(DB_BaseViewModel *)viewModel
{
    NSString *viewController = self.viewModelViewMappings[NSStringFromClass(viewModel.class)];
    NSParameterAssert([NSClassFromString(viewController) isSubclassOfClass:[DB_BaseViewController class]]);
    NSParameterAssert([NSClassFromString(viewController) instancesRespondToSelector:@selector(initWithViewModel:)]);
    return [[NSClassFromString(viewController) alloc] initWithViewModel:viewModel];
}
#import "Test1Model.h"
#import "Test1ViewController.h"
- (NSDictionary *)viewModelViewMappings
{
    return @{@"TestViewModel":@"TestController",
             @"Test1Model":@"Test1ViewController"
             };
}
@end
